package com.xiao.springes.service;

import com.xiao.springes.mapper.BookMapper;
import com.xiao.springes.model.BookBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: XiaoTing
 * @create: 2020-05-20 15:27
 * @description: book服务
 **/
@Slf4j
@Service
public class BookService {

    @Autowired
    private BookMapper bookMapper;

    /**
     * 根据作者分页查询数据
     *
     * @param author      作者
     * @return
     */
    public List<BookBean> findByAuthor(String author) {
        return bookMapper.findByAuthor(author);
    }

    /**
     * 保存记录
     *
     * @param book
     */
    public void save(BookBean book) {
        bookMapper.save(book);
    }

    /**
     * 查询所有的
     *
     * @return
     */
    public List<BookBean> findAll() {
        Page<BookBean> all = (Page<BookBean>) bookMapper.findAll();
        return all.getContent();
    }

    /**
     * 按照条件删除数据
     *
     * @param bookBean 实体
     */
    public void deleteBook(BookBean bookBean) {
        bookMapper.delete(bookBean);
    }

    public List<BookBean> findByTitle(String title){
        return bookMapper.findByTitle(title);
    }



}
